<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<base href="<%=basePath%>">

		<title>管理导航区域</title>

		<meta http-equiv="pragma" content="no-cache">
		<meta http-equiv="cache-control" content="no-cache">
		<meta http-equiv="expires" content="0">
		<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
		<meta http-equiv="description" content="This is my page">
		<link rel="stylesheet" href="css/common.css" type="text/css" />
		<link rel="stylesheet" href="css/jquery-ui-1.8.5.custom.css"
			type="text/css" />
		<script src="<%=basePath %>js/jquery-1.5.js" language="javascript">
</script>
		<style>
.my-dialog .ui-dialog-titlebar-close {
	display: none;
}
</style>
		<script src="js/table.js" language="javascript">
</script>
		<script src="<%=request.getContextPath()%>/js/pageInfo.js"
			type="text/javascript">
		</script>
		<script
			src="<%=request.getContextPath()%>/js/jquery-ui-1.8.5.custom.min.js"
			language="javascript">
		</script>
		<script src="js/ajaxfileupload.js" language="javascript">
</script>
		<script language="javascript">
$(function() {
	$("#singleImport").attr("checked", true);
	loadSubjects();
	//加载学院下拉列表
	loadColleges();
	//加载地区下拉列表
	loadAreas();
	//初始化专业下拉列表
	loadProfession($("#collegesList").val())
	$("#collegesList").change(function() {
		loadProfession($("#collegesList").val())
		$("#professionsList").trigger("change")
		if ($("#collegesList").val() == '') {//选择了珠海校区全部学院
				$("#dormType").val('true')
			} else {
				$("#dormType").val('false')
			}
			$("#dormType").trigger("change")
		})
	//初始化班级列表
	loadClasses($("#professionsList").val())
	$("#professionsList").change(function() {
		loadClasses($("#professionsList").val())
	})
	$("select").each(function() {//全部默认选择第一项
				$(this).children().first().attr("selected", "selected")
			})
	/*$("#dormType").change(function() {
		//alert($("#dormType").val()=='true')
			if ($("#dormType").val() == 'true') {//备用宿舍将不能选择专业和班级

				$("#professionsList").attr("disabled", true);
				$("#classesList").attr("disabled", true);

			} else {

				$("#professionsList").attr("disabled", false);
				$("#classesList").attr("disabled", false);
			}
		})*/

})
//加载学院下拉列表
function loadColleges() {
	var colleges
=<s:property value="colleges" escape="false"/>
			$("select#collegesList option").remove();
			for(var c in colleges){
				$("#collegesList").append("<option value='"+c+"'>"+colleges[c]+"</option>")
			}
			//$("#collegesList").append("<option value=''>珠海校区全部学院</option>")
			
		}
		function loadProfession(collegeId){
			$("select#professionsList option").remove();
			var professionMap=<s:property value="professions" escape="false"/>
			var professions=professionMap[collegeId];
			for(var p in professions){
				$("#professionsList").append("<option value='"+p+"'>"+professions[p]+"</option>")
			}
			//$("#professionsList").append("<option value=''>所有专业</option>")
		}
		function loadClasses(professionId){
			var classes=<s:property value="classes" escape="false"/>
			$("#classesList option").remove();
			for(var i=1;i<=classes[professionId];i++){
				$("#classesList").append("<option value='"+i+"'>"+i+"</option>")
			}
		}
		
		function loadAreas(){
			var areas = <s:property value="areas" escape="false"/>;
			$("select#areasList option").remove();
			for(a in areas){
				$("#areasList").append("<option value='"+a+"'>"+areas[a]+"</option>");
			}
		}
		function loadSubjects(){
			var subs = <s:property value="subjects" escape="false" />;
			$("select#subjectsList option").remove();
			for(a in subs){
				$("#subjectsList").append("<option value='"+a+"'>"+subs[a]+"</option>");
			}
			
		}

function addStu(){
	var name = $("#username").val();
	var sex = $("#sex").val();
	var idcode = $("#idcode").val();
	var examcode = $("#examcode").val();
	var stuNumber = $("#stuNumber").val();
	var stuScore = $("#stuScore").val();
	var feePayable = $("#feePayable").val();
	var unpaidFees = $("#unpaidFees").val();
	var stuPolitics = $("#stuPolitics").val();
	var areaId = $("#areasList").val();
	var subjectId = $("#subjectsList").val();
	var professionId=$("#professionsList").val();
	var collegeId=$("#collegesList").val();
	var clazz=$("#classesList").val();
	var single=$("#singleImport").attr("checked");//导入条件记录
	var regex = /^[0-9]*$/;
	var idcodeReg=/\d{17}[\dxX]|\d{15}///身份证验证的正则表达式

	
		if(single){//插入单条记录
				if(name == "" || name==null){
					alert("姓名不能为空!");
					return;
				}
				if(idcode == "" || idcode==null){
					alert("身份证号不能为空!");
					return;
				}else{
					if(!idcodeReg.test(idcode)){
						alert("身份证号格式不正确！！")
						return;
					}
					if(idcode.length!=18){
						alert("身份证号必须为18位！！")
						return;
					}
				}
				
				if(examcode == "" || examcode==null){
					alert("准考证号不能为空!");
					return;
				}else{
					if(examcode.length!=10){
						alert("准考证号必须为10位！！")
						return;
					}
				}
				
				if(feePayable == "" || feePayable==null){
					alert("应缴学费不能为空!");
					return;
				}
				if(unpaidFees == "" || unpaidFees==null){
					alert("欠费不能为空!");
					return;
				}
				if(feePayable<unpaidFees){
					alert("欠费不能大于应缴学费")
					return;
				}
				var param={};
				param.date=new Date();
				param.stuName=name;
				param.sex=sex;
				param.examCode=examcode;
				param.idCode=idcode;
				param.stuNumber = stuNumber;
				param.stuScore = stuScore;
				param.feePayable = feePayable;
				param.unpaidFees = unpaidFees;
				param.stuPolitics = stuPolitics;
				
				if(professionId!=''){
					param.professionId=professionId;
				}else{
					clazz='';
				}
				if(collegeId!=''){
					param.collegeId=collegeId;
				}else{
					professionId='';
					clazz=''
				}
				if(clazz!=''){
					param.clazz=clazz;
				}
				if(areaId!=''){
					param.areaId = areaId;
				}
				if(subjectId !=''){
					param.subjectId = subjectId;
				}
				$("#progressBar").show();
				$.post("json/addSingleStuAction",param,function(data){
					if(data.result=='')
						alert("该学生的准考证或身份证或班内序号已经存在！")
					else{
						alert("增加成功！")
						showAddStu(data.result)
						updateResultIndex()
					}
					$("#progressBar").hide();
				})
			
			}else{
				var file=$("#upload").attr("value");
				if(file==null || file==""){
					alert("请先选择上传的文件!");
					return;
				}
				var excel=file.substring(file.lastIndexOf(".")); 
				if(excel!=".xls" && excel!=".xlt"){
					alert("请上传'.xls格式的Excel文件!'");
					return;
				}
				
				$("#importErrorDiv").hide(); 
				$("#checkingImage").hide();//显示对与错的图片
				$("#checkingProgress").show();//显示处理进度条
				$("#importMessage").html("")
				//显示处理窗口
				$("#doLotImportDiv").show();
				$("#doLotImportDiv").dialog({
					modal: true,
					width:500,
					height:500,
					dialogClass: "my-dialog",
					buttons:{
						'完成':function(){
							$("#doLotImportDiv").dialog("close")
						}}
				})
				dlBtnEnable(false);
				//批量导入宿舍
				 $.ajaxFileUpload({
                        url:'json/adminUploadExcel.action?flag=3', //你处理上传文件的服务端
                        secureuri:false,
                        fileElementId:'upload',
                        dataType: 'json',
                        success: function (data, status) {
					 		error=eval("("+data.error+")");
					 		if(error.length<=0){
					 			//没有错误
					 			$("#checkingImage").show();
					 			$("#checkingProgress").hide();
					 			$("#checkingImage").attr("src","images/right.png")
					 			$("#importMessage").html("<font size='+3' color='red'>导入成功</font>")
					 			var student=eval("("+data.result+")");
					 			for(var i=0;i<student.length;i++){
					 				showAddStu(student[i])
					 			}
					 			updateResultIndex()
					 			
					 		}else{
					 			
					 			 var table=$("#importErrorTable")
					 			 $("#importMessage").html("<font size='+3' color='red'>导入失败！</font>")
					 			 $("table#importErrorTable tr:gt(0)").remove();
                           		 for(var i=0;i<error.length;i++){	 
                                  	var tr='<tr><td align="center">'+(i+1)+'</td><td align="left" ><font color="red">'+error[i]+'</font></td></tr>';
                           		 	table.append($(tr));
                           		 }
                           		 	$("table#importErrorTable tr:gt(0):even").css('background','#deefff'); 
									$("table#importErrorTable tr:gt(0):odd").css('background','#fff');
									$("#checkingImage").attr("src","images/error.png")
									$("#checkingImage").show();
									$("#checkingProgress").hide();
									$("#importErrorDiv").show();
									
					 		}
					 		dlBtnEnable(true);
 
                        },
						error: function (data, status, e)
						{	
							alert("上传失败！");
							$("#doLotImportDiv").dialog("close");
							dlBtnEnable(true);
						}
                   })
				
				//uploadDormExcel();
			}
}

//显示增加完的宿舍

		function showAddStu(stu){
			
			$("#stuList").show();
			if(typeof stu !='object')
				stu=eval("("+stu+")")
			if(!stu){
				return;
			}	
			var name = stu.studentName;
			var sex = (stu.sex == true ? '男' : '女') ;
			var idcode = stu.idCode;
			var examcode = stu.examCode;
			var stuNumber = stu.studentNumber;
			var stuScore = stu.score;
			var stuSubject = stu.subject;
			var unpaidFees = stu.unpaidFees;
			var stuPolitics =stu.politicsStatus;
			var area = stu.area;
			var collegeName=stu.college;
			var clazz=stu.profession + stu.clazz + "班";
			
			var tr=	'<tr><td align="center" name="addRecodeIndex"></td><td align="center">'+name+'</td><td align="center">'+sex+'</td><td align="center">'+stuNumber+'</td><td align="center">'+idcode+'</td><td align="center"> '+examcode+'</td><td align="center">'+stuSubject+'</td><td align="center">'+collegeName+'</td><td align="center">'+clazz+'</td><td align="center">'+area+'</td><td align="center">'+stuScore+'</td><td align="center">'+stuPolitics+'</td><td align="center">'+unpaidFees+'</td></tr>';
			$("#stuAddTable tr:eq(0)").after($(tr));

			$("table#stuAddTable tr:gt(0):even").css('background','#deefff'); 
			$("table#stuAddTable tr:gt(0):odd").css('background','#fff');
		}
		function updateResultIndex(){
			$("td[name='addRecodeIndex']").each(function(i,v){
				$(this).html(i+1)
			})
		}
	//上传学生表Excel
	function uploadStuExcel(){
		alert("up");
		var file=$("#upload").attr("value");
		if(file==null || file==""){
			alert("请选择上传的文件!");return;
		}
		var excel=file.substring(file.lastIndexOf(".")); 
		if(excel!=".xls" && excel!=".xlt"){
			alert("请上传'.xls格式的Excel文件!'");
			return;
		}
		$("#import_stu_excel_form").attr("action","adminUploadExcel.action?flag=3").submit();
		//$("#import_Dorm_excel_form");
	}
	
	function exportStuExcel() {
	
		$("#import_stu_excel_form").attr("action","exportStudentExcelDemo.action").submit();
	}
/*	$(function(){
		var stuList=[];
		
		if('${sessionScope.stuList}'!=''){
		
			stuList='${sessionScope.stuList}';
			stuList=eval("("+stuList+")");
		}
		
		for(var i=0;i<stuList.length;i++){
			
			showAddStu(eval(stuList[i]));
		}
	})*/
	$(function(){
		$("#examcode").keyup(function(){//准考 证限制只能输入数字
			$(this).val($(this).val().replace(/[^0-9]/g,""))
		})
		$("#stuNumber").keyup(function(){//班内序号限制只能输入数字
			$(this).val($(this).val().replace(/[^0-9]/g,""))
		})
		$("#stuScore").keyup(function(){//分数限制只能输入数字
			$(this).val($(this).val().replace(/[^0-9]/g,""))
		})
		$("#feePayable").keyup(function(){//学费只能输入数字
			$(this).val($(this).val().replace(/[^0-9]/g,""));
		})
		$("#unpaidFees").keyup(function(){//欠款金额限制只能输入数字
			$(this).val($(this).val().replace(/[^0-9]/g,""))
		})

	
	})
	
		//控制按钮是否可用的函数.

function dlBtnEnable(enable)

{

    var dlgButton = $('.ui-dialog-buttonpane button');

    if (enable) {

        dlgButton.attr('disabled', '');

        dlgButton.removeClass('ui-state-disabled');

    } else {

        dlgButton.attr('disabled', 'disabled');

        dlgButton.addClass('ui-state-disabled');

    }

}
</script>
	</head>

	<body>
	<div class="adminhead">
			<jsp:include page="head.jsp"></jsp:include>
		</div>
		<div class="adminmain">
			<div class="left">
				<jsp:include page="leftMenu.jsp"></jsp:include>
			</div>
			<div class="right">
				<div id="nav">
			<ul>
				<li class="bg_image_onclick">
					导入学生信息
				</li>
			</ul>
		</div>
		<div id="sub_info">
			&nbsp;&nbsp;
			<img src="images/hi.gif" />
			&nbsp;
			<span id="show_text">欢迎进入新生报告系统后台管理!</span>您现在正在：信息导入&gt;&gt;&gt;导入学生信息
		</div>

		<div id="man_zone">
			<!--************************************************************-->
			<table width="950" border="0" align="center" cellpadding="1"
				cellspacing="5" height="70">
				<tr>
					<td width="74%">
						<div>
							<table width="100%" border="0" cellspacing="2" cellpadding="0"
								id="d1">
								<tr>
									<td align="right">
										姓名：
									</td>
									<td>
										<input type="text" size="15" id="username" />
									</td>
									<td align="right">
										性别：
									</td>
									<td>
										<select name="select2" id="sex">
											<option value="true">
												男
											</option>
											<option value="false">
												女
											</option>
										</select>
										&nbsp;&nbsp;&nbsp;类型:
										<select id="subjectsList">
											<option>
												--请选择--
											</option>
										</select>
									</td>
								</tr>
								<tr>
									<td align="right">
										身份证号：
									</td>
									<td>
										<input type="text" size="18" id="idcode" />
									</td>
									<td align="right">
										准考证号：
									</td>
									<td>
										<input type="text" size="15" id="examcode" />
									</td>
								</tr>
								<tr>
									<td align="right">
										班内序号：
									</td>
									<td>
										<input type="text" size="7" id="stuNumber" />
									</td>
									<td align="right">
										高考分数：
									</td>
									<td>
										<input type="text" size="15" id="stuScore" />
									</td>
								</tr>
								<tr>
									<td align="right">
										地区：
									</td>
									<td>
										<select name="" id="areasList">
											<option>
												--请选择地区--
											</option>
										</select>
									</td>
									<td align="right">
										政治面貌：
									</td>
									<td>
										<input type="text" size="15" id="stuPolitics" />
									</td>
								</tr>
								<tr>
									<td align="right">
										应缴学费：
									</td>
									<td>
										<input type="text" size="15" id="feePayable" />
									</td>
									<td align="right">
										欠费金额：
									</td>
									<td>
										<input type="text" size="15" id="unpaidFees" />
									</td>
								</tr>
								<tr>
									<td align="right">
										学院：
									</td>
									<td>
										<select name="" id="collegesList">
											<option>
												--请选择学院--
											</option>
										</select>
									</td>
									<td align="right">
										专业名称:
									</td>
									<td>
										<select name="" id="professionsList">
											<option>
												--请选择专业--
											</option>
										</select>
										班级：
										<select name="" id="classesList">
											<option>
												--请选择班级--
											</option>
										</select>
									</td>
								</tr>
							</table>

							<div id="d2" style="display: none; padding-left: 20px;">

								<form action="" id="import_stu_excel_form" method="post"
									enctype="multipart/form-data">
									<input type="file" name="upload" id="upload" />
									&nbsp;&nbsp;
									<input type="button" value="下载模板" onclick="exportStuExcel()" />
								</form>
								<font color="red">请选择下载模版,填写内容后再导入</font>
							</div>

						</div>
					</td>
					<td width="19%" style="border-left: 1px dotted red;">
						<div>
							<input name="a" type="radio" value="" checked="checked"
								id="singleImport"
								onclick="document.getElementById('d1').style.display='block';document.getElementById('d2').style.display='none';" />
							单个导入
						</div>
						<div>
							<input name="a" type="radio" value=""
								onclick="document.getElementById('d1').style.display='none';document.getElementById('d2').style.display='block';" />
							批量导入
						</div>
					</td>
					<td width="7%">
						<input type="button" value="执行" onclick="addStu()" />
					</td>
				</tr>
			</table>
			<!--************************************************************-->
			<div id="progressBar" style="display: none">
				<!-- 进度圈 -->
				<center>
					<img src="images/loading.gif" />
				</center>
			</div>
			<div id="stuList" style="display: none">

				<h2 style="text-align: center; color: red;">
					刚增加的学生列表
				</h2>
				<table width="950" height="31" border="0" align="center"
					cellpadding="0" cellspacing="1" class="t1"
					style="margin-top: 20px; border: 1px solid #5cb0ff;"
					id="stuAddTable">
					<tr style="color: #000;">
						<th height="20" align="center">
							序号
						</th>
						<th height="20" align="center">
							姓名
						</th>
						<th height="20" align="center">
							性别
						</th>
						<th height="20" align="center">
							班内序号
						</th>
						<th height="20" align="center">
							身份证号
						</th>
						<th height="20" align="center">
							准考证号
						</th>
						<th height="20" align="center">
							学生类型
						</th>
						<th height="20" align="center">
							学院
						</th>
						<th height="20" align="center">
							班级
						</th>
						<th height="20" align="center">
							地区
						</th>
						<th height="20" align="center">
							高考分数
						</th>
						<th height="20" align="center">
							政治面貌
						</th>
						<th height="20" align="center">
							欠费金额
						</th>
					</tr>
				</table>
			</div>
			<!--************************************************************-->
		</div>
		<!--                   批量导入时的弹出div -->
		<div id="doLotImportDiv" title="批量导入学生" style="display: none">
			<table width="100%">
				<tr>
					<td align="left">
						<font color="red" size="2px">正在导入。。。</font>
						<br />
					</td>
					<td align="right">
						<img src="images/right.png" alt="" width="30px" id="checkingImage" />
					</td>
				</tr>
				<tr>
					<td colspan="2">
						<img src="images/progressBar.gif" alt="正在导入。。。"
							id="checkingProgress" />
						<div id="importMessage">

						</div>
					</td>
				</tr>
				<tr>
					<td>

						<div id="importErrorDiv" style="display: none">
							<table id="importErrorTable" width="100%" border="0" style=""
								class="t1">
								<tr style="font-size: 18px; font-weight: bold; color: red">
									<th width="10%" align="center">
										序号
									</th>
									<th align="center">
										错误信息
									</th>
									<tr>
										<tr>
											<td align="center">
												1
											</td>
											<td align="center">
												宿舍号重复
											</td>
										</tr>
							</table>
						</div>
					</td>
				</tr>
			</table>
			<div>


			</div>
		</div>
		
			</div>
		</div>
		<div class="adminfooter">
			<jsp:include page="footer.jsp"></jsp:include>
		</div>
		
	</body>
</html>
